#include <stdio.h>
#include <stdlib.h>
void merge(int A[], int m, int B[], int n) {
        if(n == 0)
            return;
        if(m == 0)
        {
            for(int i = 0; i < n; i++)
                A[i] = B[i];
            return;
        }    
        
        int a = 0;
        int b = 0;
        int merged_count = 0;
        int temp[m];
        
        //copy A
        for(int i = 0; i < m; i++)
            temp[i] = A[i];
        printf("After copy\n");
        //merge
        while((a < m)&&(b < n))
        {
            if(temp[a]<=B[b])
            {
                A[merged_count++] = temp[a++];
            }
            else
            {
                A[merged_count++] = B[b++];
            }            
        }
        while(a<m)
            A[merged_count++] = temp[a++];
        while(b<n)
            A[merged_count++] = B[b++];
    }
int main(int argc, char const *argv[])
{
    int lengtha = 4;
    int lenghtb = 5;
    int A[10] = {1, 3, 4, 5};
    int B[5] = {2,4,5,6,7};
    merge(A, lengtha, B, lenghtb);

    for (int i = 0; i < lengtha + lenghtb; ++i)
    {
        printf("%d\n", A[i]);
    }

    return 0;
}